/**
 * 分页列表 mixins
 * 分页参数 列表控制
 */

import PagerTabel from '@/components/custom/PagerTabel/index.vue'
import SearchForm from '@/components/custom/SearchForm/index.vue'

export default {
  components: {
    PagerTabel,
    SearchForm
  },
  data() {
    return {
      total: 0,
      pageSize: 10,
      currentPage: 1,
      tableData: [],
      loading: false,
      fields: [],
      rowKey: []
    }
  },
  methods: {
    // 搜索
    searchList() {
      this.currentPage = 1
      this.getList()
    },
    // 加载列表 - 不同列表请覆盖该方法
    requestListApi(page) {
      return Promise.resolve({ list: [], total: 0 })
    },
    // 获取更多列表
    async getList() {
      this.loading = true
      try {
        let page = {
          pageSize: this.pageSize,
          currentPage: this.currentPage
        }
        let res = await this.requestListApi(page)
        this.loading = false
        this.handelList(res)
      } catch (error) {
        console.log(error, '-->>> getList error')
        this.loading = false
      }
    },
    // 数据整理
    listFormatData(list) {
      return list
    },
    // 处理列表数据
    handelList(res) {
      this.loading = false
      this.total = res ? res.total : 0
      if (!res || !res.list) {
        this.tableData = []
      } else {
        this.tableData = this.listFormatData(res.list)
      }
    }
  }
}
